# 先创建一个示例文件
# with open("E:\python\python-learning-journey\11-12\故事.txt", "w", encoding="utf-8") as f:
#     f.write("第一行内容\n第二行内容\n第三行内容\n")

# 1. read方法读文件（正确的语法）
print("=== read方法 ===")
with open("E:\python\python-learning-journey\11-12\故事.txt", "r", encoding="utf-8") as f:
    content = f.read()
    print(content)

# 2. readline方法读文件
print("=== readline方法 ===")
with open("E:\python\python-learning-journey\11-12\故事.txt", "r", encoding="utf-8") as f:
    line = f.readline()
    while line != "":
        print(line.strip())  # 使用strip()去除换行符
        line = f.readline()

# 3. readlines方法读文件（修正了缩进）
print("=== readlines方法 ===")
with open("E:\python\python-learning-journey\11-12\故事.txt", "r", encoding="utf-8") as f:
    lines = f.readlines()
    for line in lines:  # 这里冒号后面要换行并缩进
        print(line.strip())  # 正确的缩进